package com.mangosteen.interviewji.utils;

import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class EsAvailable {

    @Resource
    private  ElasticsearchRestTemplate elasticsearchRestTemplate;

    public boolean isElasticsearchAvailable(){
        try {
            elasticsearchRestTemplate.search(new NativeSearchQueryBuilder().build(), Object.class);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}
